package com.wenyl.threads.lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author Swimming Dragon
 * @description: TODO
 * @date 2024年11月01日 15:12
 */
public class PessimisticLock {
    public static int inc = 0;
    private final ReentrantLock lock = new ReentrantLock();
    public void synchronizedIncTask(){
        synchronized (PessimisticLock.class){
            inc++;
        }
    }
    public void lockIncTask(){
        lock.lock();
        try{
            inc++;
        }finally {
            lock.unlock();
        }
    }
}
